/**************************************************************************//**
 * @file     main.c
 * @version  V
 * $Revision: 
 * $Date: 
 * @brief    
 *
 * @note
 * Copyright (C) 2013 JiuTu Technology Corp. All rights reserved.
 ******************************************************************************/
#include "stri.h"
#include "stri_simulink.h"
#include "pulse.h"
#include "stdio.h"
#include "fun_list.h"
#include "sys_task.h"

void stri_control(void);
void simulink_run(void);
void simulink_in(void);

char binit = 0;

/*---------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------*/
void stri_main(void) 
{ 
	if(!binit)
	{
		binit = 1;
		sim_obj.neng_liang.nei = 20 * 20000;
		sim_obj.neng_liang.wai = 20 * 40000;
		sim_obj.neng_liang.obj = 20 * 6000;

		sim_obj.water.f_shui_wei = 49;
		sim_obj.press.kong_qi_bili = 1;
		
		stri.cmd.start = 1;
	}
	
	stri_control();

	if(sys_st.pulse.pulse_100ms)
	{
		simulink_run();
	}
		
	simulink_in();
	
	if(sys_st.pulse.pulse_1s)
	{
		/*
		printf("air temp : %5.1f, obj temp : %5.1f, ext temp : %5.1f, press : %5.1f\n",
		sim_obj.temp.f_nei, sim_obj.temp.f_obj, sim_obj.temp.f_wai, sim_obj.press.f_press
		);
		*/
	}
}
FUN_LIST_EXPORT(napp, stri_main);


void simulink_in(void)
{
	sim_obj.temp.ft = 100;
	
	sim_obj.heat.main_heat_period = stri.heat.main_period / 3;
	sim_obj.heat.main_heat_duty = stri.heat.main_duty / 3;
	sim_obj.heat.ext_heat_period = stri.heat.ext_period / 3;
	sim_obj.heat.ext_heat_duty = stri.heat.ext_duty / 3;
	sim_obj.press.b_air_out = stri.out.air_out;
	
	sim_obj.neng_liang.re_rong_liang_nei = 20000;
	sim_obj.neng_liang.re_rong_liang_wai = 40000;
	sim_obj.neng_liang.re_rong_liang_obj = 6000;
	
	if(stri.out.fan_dis_req)
	{
		stri.out.fan_dis_req = 0;
		sim_obj.b_feng_shan = 0;
	}
	if(stri.out.fan_en_req)
	{
		stri.out.fan_en_req = 0;
		sim_obj.b_feng_shan = 1;
	}
	
	sim_obj.water.b_bu_shui = stri.out.wat_add;
	sim_obj.water.b_pai_shui = stri.out.wat_out;
}


const void * stri_step_name_get(char cn)
{
	switch (stri.step.now)
	{
		case STRISTEP_IDLE:
			return cn?"空闲":"IDLE";
		case STRISTEP_CHECK:
			return cn?"自检":"CHECK";
		case STRISTEP_ORDER_TIME:
			return cn?"预约":"OT";
		case STRISTEP_ORDER_HEAT:
			return cn?"预热":"OR";
		case STRISTEP_PRESSURIZE:
			return cn?"正压":"PRES";
		case STRISTEP_VACUUM:
			return cn?"真空":"VACU";
		case STRISTEP_PRE_VACUUM:
			return cn?"预空":"PVCU";
		case STRISTEP_PRE_HEAT:
			return cn?"加热":"PHET";
		case STRISTEP_HEAT:
			return cn?"加热":"HEAT";
		case STRISTEP_DELAY:
			return cn?"延时":"DALY";
		case STRISTEP_PRESS_DO:
			return cn?"压力":"DUAL";
		case STRISTEP_PRESS_UP:
			return cn?"升压":"P UP";
		case STRISTEP_PRESS_KEEP:
			return cn?"保压":"KEEP";
		case STRISTEP_AUTO_COOL:
			return cn?"自冷":"COL1";
		case STRISTEP_AIROUT:
			return cn?"排气":"AOUT";
		case STRISTEP_WATOUT:
			return cn?"排水":"WOUT";
		case STRISTEP_DRY:
			return cn?"干燥":"DRY";
		case STRISTEP_COMP_COOL:
			return cn?"冷却":"COL2";
		case STRISTEP_WARM:
			return cn?"保温":"WARM";
		case STRISTEP_COMP:
			return cn?"完成":"COMP";
		case STRISTEP_END:
			return cn?"结束":"END";
		default:
			return cn?"错误":"BUG";
	}
}





/*
void lib_check_hook(int cnt)
{

}

void lib_os_lock(void)
{

}

void lib_os_unlock(void)
{

}
*/
